<?php

namespace XWAM\Addon\POrgDocument\Controller;

/**
 * DocumentCategoryController类
 *
 * @since 1.0 <2015-10-22> SoChishun <14507247@qq.com> Added.
 */
class ChannelsController extends \XWAM\Controller\AppbaseController {

    public function channel_list() {
        $this->assign('type_list', array('DOCUMENT' => array('title' => '文章', 'url' => AddonU('Documents/document_list')), 'FILE' => array('title' => '文件', 'url' => AddonU('File/file_list'))));
        $this->assign('tree', AddonD('DocumentCategory')->select_tree());
        $this->display_cpp();
    }

    public function channel_edit($id = 0, $pid = 0) {
        $data = array();
        if ($id) {
            $data=AddonD('DocumentCategory')->find($id);
        }
        if ($pid) {
            $data['pid'] = $pid;
        }
        $this->assign('data', $data);
        $this->display();
    }

    public function channel_edit_save() {
        $result = AddonD('DocumentCategory')->save_category();
        $this->dialogJump($result['status'],$result['info']);
    }

    public function get_channel_tree_json($type_id=0,$pid=0) {
        $options=array();
        if($type_id){
            $options['where']['type_id']=$type_id;
        }
        if($pid){
            $options['where']['pid']=$type_id;
        }
        $data = AddonD('DocumentCategory')->select_json_tree($options);
        $this->ajaxReturn($data);
    }
    
    function change_status($id, $status){
        $this->ajaxReturn(AddonD('DocumentCategory')->change_status($id,$status));
    }
    function change_sort($id, $sort){
        $this->ajaxReturn(AddonD('DocumentCategory')->change_sort($id,$sort));
    }
    function channel_delete($id=''){
        $this->ajaxReturn(AddonD('DocumentCategory')->delete_channel($id));
    }
}
